﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace NutriLeaf.Web.Core.Food
{
    public class FoodTemperature:IFoodTemperature
    {
        public void AddFoodTemperature(int foodId, float startTemp, float endTemp, ref Model.NutriLeafDBEntities context)
        {
            Model.FoodTemperature temperature = new Model.FoodTemperature();
            temperature.FoodID = foodId;
            temperature.TemperatureStart = startTemp;
            temperature.TemperatureEnd = endTemp;
            context.FoodTemperatures.AddObject(temperature);
            context.SaveChanges();
        }

        public void AddFoodTemperature(Model.FoodTemperature foodTemp, ref Model.NutriLeafDBEntities context)
        {
            context.FoodTemperatures.AddObject(foodTemp);
            context.SaveChanges();
        }

        public void RemoveFoodTemperature(int foodTemperatureId, ref Model.NutriLeafDBEntities context)
        {
            if (context.FoodTemperatures.Where(p => p.FoodTemperatureID == foodTemperatureId).Count() != 0) {
                context.FoodTemperatures.DeleteObject(context.FoodTemperatures.Where(p => p.FoodTemperatureID==foodTemperatureId).First());
                context.SaveChanges();
            }
        }

        public List<Model.FoodTemperature> GetFoodTemperatures(int foodId, ref Model.NutriLeafDBEntities context)
        {
            return context.FoodTemperatures.Where(p => p.FoodID == foodId).ToList();
        }
    }
}